<?php

App::uses('AppController', 'Controller');
App::uses('Area', 'Model');
App::uses('Line', 'Model');
App::uses('Moe', 'Model');
App::uses('Workstation', 'Model');
App::uses('WorkstationConfig', 'Model');
App::uses('CertificationDetail', 'Model');
App::uses('Certification', 'Model');
App::uses('Categorization', 'Model');
App::uses('Shift', 'Model');
App::uses('User', 'Model');
App::uses('UserTheme', 'Model');
App::uses('UserArea', 'Model');
App::uses('Attempt', 'Model');
App::uses('Evaluation', 'Model');
App::uses('EvaluationDetail', 'Model');
App::uses('Theme', 'Model');
App::uses('TeamUser', 'Model');
App::uses('Test', 'Model');

class Moe3Controller extends AppController {

    private $lineId = '54de036a-24c8-4125-9c69-1e1c1b09678d';

    public function beforeFilter() {
        $this->Auth->allow();
        $this->loadModel('Area');
        $this->loadModel('Line');
        $this->loadModel('Moe');
        $this->loadModel('Shift');
        $this->loadModel('User');
        $this->loadModel('UserTheme');
        $this->loadModel('TeamUser');
        $this->loadModel('UserLine');
        $this->loadModel('Workstation');
        $this->loadModel('WorkstationConfig');
        $this->loadModel('CertificationDetail');
        $this->loadModel('Certification');
        $this->loadModel('Categorization');
        $this->loadModel('Attempt');
        $this->loadModel('Evaluation');
        $this->loadModel('EvaluationDetail');
        $this->loadModel('Theme');
        $this->loadModel('UserArea');
        $this->loadModel('Link');
        $this->loadModel('Test');
        parent::beforeFilter();
    }

    public function index() {
        set_time_limit(360000);
        $this->request->allowMethod('get');
        $path = APP . WEBROOT_DIR . "/files/moe3.csv";
        $handle = @fopen($path, "r");
        if ($handle) {
            $i = 0;
            while (($buffer = fgets($handle)) !== false) {
                $i++;
                //if ($i < 60) continue;
                //if($i>1) break;
                $parts = explode(',', $buffer);
                $this->log('----' . $parts[2] . '----' . $i);
                $usr = $this->user($parts);
                $usrLine = $this->userLine($usr, $this->lineId, $usr['admission_date'], $parts[12]);
                //// EVALUACIONES
                $n = 'inicial';
                $this->evaluacion($this->lineId, $n, $usr, $parts[13], $parts[14], $parts[15], $parts[16], $parts[17], $parts[18], $parts[19], $parts[20], $parts[21], $parts[22], $parts[23], $parts[24]);
                $n = 'intermedio';
                $this->evaluacion($this->lineId, $n, $usr, $parts[25], $parts[26], $parts[27], $parts[28], $parts[29], $parts[30], $parts[31], $parts[32], $parts[33], $parts[34], $parts[35], $parts[36]);
                $n = 'avanzado';
                $this->evaluacion($this->lineId, $n, $usr, $parts[37], $parts[38], $parts[39], $parts[40], $parts[41], $parts[42], $parts[43], $parts[44], $parts[45], $parts[46], null, null);
                // CERTIFICACIONES
                $this->frl($parts, $usr);
                $this->ic($usrLine, $parts, $usr);
                $this->tev($usrLine, $parts, $usr);
                $this->dve5nc($usrLine, $parts, $usr);
                $this->dve52nc($usrLine, $parts, $usr);
                $this->cover($usrLine, $parts, $usr);
                $this->maquinados($usrLine, $parts, $usr);
                $this->moldeo($usrLine, $parts, $usr);
            }
            fclose($handle);
        }
        $this->redirect(array('controller' => 'Alta', 'action' => 'index'));
        $this->set('title', __('Migracion MOE3'));
        $this->layout = 'base';
    }
    
    public function user($parts) {
        $nomina = trim($parts[2]);
        $user = $this->User->getByNomina($nomina);
        if (isset($user['User']) === false) {
            $usrData = array(
                'id' => String::uuid(),
                'category_id' => 'aa0ac014-02c0-11e4-995e-24b6fdfa405b',
                // Se llenan al llama la funcion name
                // Full name
                // name
                // last name 1
                // last name 2
                'nomina' => $nomina,
                'us3r' => $nomina,
                // curp se llena con la funcion curp
                'support' => User::SUPPORT_OFF,
                'is_external' => User::EXTERNAL_OFF,
                // p4ss se llena con la funcion curp
                // admission_date se llena con la funcion admissionDate
                'permissions' => 0,
                'status' => User::STATUS_ENABLED,
            );
            $this->name($usrData, trim($parts[3]));
            $this->curp($usrData, trim($parts[4]));
            $this->admissionDate($usrData, trim($parts[5]));
            $r = $this->User->save($usrData);
            if ($r === false) {
                var_dump($usrData);
            }
            $this->User->clear();
            return $usrData;
        }
        return $user['User'];
    }

    public function name(&$user, $value) {
        $len = strlen($value);
        if ($len < 10) {
            $this->log($user['nomina'] . ' NOMBRE MUY CORTO ' . $value);
        }
        $user['full_name'] = utf8_encode($value);
    }

    public function curp(&$user, $value) {
        $len = strlen($value);
        if ($len < 18) {
            $this->log($user['nomina'] . ' CURP ERRONEA ' . $value);
            $value = null;
        }
        $user['curp'] = $value;
        $user['p4ss'] = $value === null ? 'temporal' : $value;
    }

    public function admissionDate(&$user, $value)
    {
        $admissionDate = null;
        $currentDate = new DateTime();
        $user['days'] = 0;
        try {
            $dt = DateTime::createFromFormat('d/m/Y', $value);
            $interval = $currentDate->diff($dt, true);
            $admissionDate = $dt->format('Y-m-d');
            $user['days'] = $interval->format('%a');
        } catch (Exception $exc) {
            $this->log($user['nomina'] . ' FECHA DE INGRESO ERRONEA ' . $value);
        }
        $user['admission_date'] = $admissionDate;
    }

    public function userLine($usrData, $lineId, $fechaIngreso, $value)
    {
        $fechaIngreso = new DateTime($fechaIngreso);
        $dt = new DateTime();
        $interval = $dt->diff($fechaIngreso, true);
        $fieldsUserLine = array(
            'assign_date' => '"' . $fechaIngreso->format('Y-m-d') . '"',
            'days' => (int)$interval->format('%a'),
        );
        $this->level($fieldsUserLine, $usrData, trim($value));
        $this->UserLine->updateUserLine($fieldsUserLine, $usrData['id'], $lineId);
        return $fieldsUserLine;
    }

    public function level(&$usrLine, $usr, $value) {
        $nameLevel = trim(strtolower($value));
        $level = null;
        switch ($nameLevel) {
            case '':
            case 'nada':
                $level = '54cfaefd-4784-469b-969a-080c1b09678d';
                break;
            case 'inicial':
                $level = '54cfb6a3-a4c8-41ab-98ee-080c1b09678d';
                break;
            case 'intermedio':
                $level = '54cfb5b9-e9b4-421c-af47-080c1b09678d';
                break;
            case 'avanzado':
                $level = '54cfb605-07bc-4590-9b2a-080c1b09678d';
                break;
            default:
                $this->log($usr['nomina'] . ' NIVEL ERRONEO ' . $value);
                break;
        }
        $usrLine['level_excel'] = '"' . $level . '"';
    }

    public function evaluacion($lineId, $testName, $usr, $t1, $t2, $t3, $t4, $aq1, $ad1, $aq2, $ad2, $aq3, $ad3, $aq4, $ad4)
    {
        $test = $this->Test->getByNameAndLine($testName, $lineId);
        $testId = $test['Test']['id'];
        if ($t1 !== null)
            $t1 = trim($t1);
        if ($t2 !== null)
            $t2 = trim($t2);
        if ($t3 !== null)
            $t3 = trim($t3);
        if ($t4 !== null)
            $t4 = trim($t4);
        if ($t1 === '' && $t2 === '' && $t3 === '' && $t4 === '') {
            return;
        }
        $evaluationId = String::uuid();
        $evaluationData = array(
            'id' => $evaluationId,
            'user_id' => $usr['id'],
            'test_id' => $testId,
            'start' => null,
            'end' => null,
            'life' => null,
            'status' => 1,
            'success' => 0,
            'training' => 0,
        );
        $this->Evaluation->save($evaluationData);
        $this->Evaluation->clear();
        if ($t1 != null) {
            $t1 = strtolower($t1) === 'ok' ? 100 : 0;
            $this->addTheme($t1, $evaluationId, $testId, 0);
        }
        if ($t2 != null) {
            $t2 = strtolower($t2) === 'ok' ? 100 : 0;
            $this->addTheme($t2, $evaluationId, $testId, 1);
        }
        if ($t3 != null) {
            $t3 = strtolower($t3) === 'ok' ? 100 : 0;
            $this->addTheme($t3, $evaluationId, $testId, 2);
        }
        if ($t4 != null) {
            $t4 = strtolower($t4) === 'ok' ? 100 : 0;
            $this->addTheme($t4, $evaluationId, $testId, 3);
        }
        $this->addAttempt($evaluationId, $aq1, $ad1, $usr, $testName);
        $this->addAttempt($evaluationId, $aq2, $ad2, $usr, $testName);
        $this->addAttempt($evaluationId, $aq3, $ad3, $usr, $testName);
        $this->addAttempt($evaluationId, $aq4, $ad4, $usr, $testName);
    }

    private function addTheme($t1, $evaluationId, $testId, $i)
    {
        $theme = $this->Theme->getByTestAndOrden($testId, $i);
        $detailData = array(
            'id' => String::uuid(),
            'theme_id' => $theme['Theme']['id'],
            'evaluation_id' => $evaluationId,
            'qualification' => $t1,
            'evaluation_date' => null, // Desconocemos la fecha cuando se evaluo
        );
        $this->EvaluationDetail->save($detailData);
        $this->EvaluationDetail->clear();
    }

    private function addAttempt($evaluationId, $cal, $date, $usr, $testName)
    {
        $cal = str_replace(',', '.', $cal);
        if ($cal === null)
            return;
        $cal = trim($cal);
        if ($cal === '')
            return;
        $cal = ($cal === 'OK' ? 100 : $cal);
        if (is_numeric($cal) === true) {
            $d = DateTime::createFromFormat('d/m/Y', $date);
            $attemptData = array(
                'id' => String::uuid(),
                'evaluation_id' => $evaluationId,
                'application_date' => $d ? $d->format('Y-m-d') : null,
                'qualification' => (double)$cal,
                'status' => 1,
            );
            if ($attemptData['application_date'] === null) {
                $msg = $usr['nomina'] . ' ' . $testName . ' FECHA ERRONEA ' . $date;
                $this->log($msg, LOG_ERR);
            }
            $this->Attempt->save($attemptData);
            $this->Attempt->clear();
        } else {
            $msg = $usr['nomina'] . ' ' . $testName . ' CALIFICACION ERRONEA ' . $cal;
            $this->log($msg, LOG_ERR);
        }
    }

    public function frl($parts, $usr)
    {
        $lineId = '54de036a-24c8-4125-9c69-1e1c1b09678d';
        // CERTIFICACIONES
        $n = '05 CORTE DE MANGUERA';
        $this->certification($n, $usr, $parts, 62, $lineId);
        $n = '015  ENSAMBLE DE PROTECCION';
        $this->certification($n, $usr, $parts, 70, $lineId);
        $n = '025  ENSAMBLE DE CONECTORES Y MANGUERA';
        $this->certification($n, $usr, $parts, 78, $lineId);
        $n = '035 ENSAMBLE DE CONECTORES Y MANGUERAS';
        $this->certification($n, $usr, $parts, 86, $lineId);
        $n = '045 ENSAMBLE DE CONECTORES Y MANGUERAS';
        $this->certification($n, $usr, $parts, 94, $lineId);
        $n = '055  ENSAMBLE FINAL DE FRL';
        $this->certification($n, $usr, $parts, 102, $lineId);
        $n = '065 ENSAMBLE DE CONECTORES Y MANGUERAS';
        $this->certification($n, $usr, $parts, 110, $lineId);
        $n = '070 PRUEBA DE FUGA EN MANGUERA';
        $this->certification($n, $usr, $parts, 118, $lineId);
        $n = '075 ENSAMBLE DE PROTECCIONES ABIERTAS';
        $this->certification($n, $usr, $parts, 126, $lineId);
        $n = '085 ENSAMBLE DE CLIPS';
        $this->certification($n, $usr, $parts, 134, $lineId);
        $n = '090 INSPECCION 100';
        $this->certification($n, $usr, $parts, 142, $lineId);
        $n = '095 EMPAQUE';
        $this->certification($n, $usr, $parts, 150, $lineId);
    }

    public function certification($workstationName, $user, $parts, $i, $lineId = null) {
        if ($lineId === null)
            $lineId = $this->lineId;
        $workstation = $this->Workstation->getByLineAndDescription($lineId, $workstationName);
        $workstationId = $workstation['Workstation']['id'];
        $ec = trim($parts[$i + 1]);
        $ef = trim($parts[$i + 2]);
        $vc = trim($parts[$i + 3]);
        $vf = trim($parts[$i + 4]);
        $cc = trim($parts[$i + 5]);
        $cf = trim($parts[$i + 6]);
        if ($ec === '' && $vc === '' && ($cc === '' || $cc === null)) {
            return;
        }
        $this->Workstation->id = $workstationId;
        $w = $this->Workstation->read();
        $certificationId = String::uuid();
        $certificationData = array(
            'id' => $certificationId,
            'user_id' => $user['id'],
            'workstation_id' => $workstationId,
            'start' => null,
            'end' => null,
            'life' => null,
            'status' => Certification::STATUS_ENABLED,
            'success' => 0,
            'training' => 1,
        );
        $this->Certification->save($certificationData);
        $this->Certification->clear();
        $def = null;
        $dcf = null;
        $dvf = null;
        if ($ec != '') {
            $ec = str_replace(',', '.', $ec);
            try {
                $def = DateTime::createFromFormat('d/m/Y', $ef, new DateTimeZone('America/Mexico_City'));
                if ($def === false)
                    $def = null;
                else {
                    $def = $def->format('Y-m-d');
                }
                if (is_numeric($ec) === true) {
                    $wc = $this->WorkstationConfig->getByWorkstationAndName($workstationId, 'Evaluación en piso');
                    $detailData = array(
                        'id' => String::uuid(),
                        'certification_id' => $certificationId,
                        'workstation_config_id' => $wc['WorkstationConfig']['id'],
                        'qualification' => (double) $ec,
                        'certification_date' => $def,
                        'status' => 1,
                    );
                    $this->CertificationDetail->save($detailData);
                    $this->CertificationDetail->clear();
                } else {
                    $msg = $user['nomina'] . ' ' . $workstationName . ' Evaluación CALIFICACION ERRONEA ' . $ec;
                    $this->log($msg, LOG_ERR);
                }
            } catch (Exception $exc) {
                $msg = $user['nomina'] . ' ' . $workstationName . ' Evaluación FECHA ERRONEA ' . $ef;
                $this->log($msg, LOG_ERR);
            }
        }
        if ($vc != '') {
            $vc = str_replace(',', '.', $vc);
            try {
                $dvf = DateTime::createFromFormat('d/m/Y', $vf, new DateTimeZone('America/Mexico_City'));
                if ($dvf === false)
                    $dvf = null;
                else {
                    $dvf = $dvf->format('Y-m-d');
                }
                if (is_numeric($vc) === true) {
                    $wc = $this->WorkstationConfig->getByWorkstationAndName($workstationId, 'Validación en piso');
                    $detailData = array(
                        'id' => String::uuid(),
                        'certification_id' => $certificationId,
                        'workstation_config_id' => $wc['WorkstationConfig']['id'],
                        'qualification' => (double) $vc,
                        'certification_date' => $dvf,
                        'status' => 1,
                    );
                    $this->CertificationDetail->save($detailData);
                    $this->CertificationDetail->clear();
                } else {
                    $msg = $user['nomina'] . ' ' . $workstationName . ' Validación CALIFICACION ERRONEA ' . $vc;
                    $this->log($msg, LOG_ERR);
                }
            } catch (Exception $exc) {
                $msg = $user['nomina'] . ' ' . $workstationName . ' validación FECHA ERRONEA ' . $vf;
                $this->log($msg, LOG_ERR);
            }
        }
        if ($cc != '') {
            $cc = str_replace(',', '.', $cc);
            try {
                $dcf = DateTime::createFromFormat('d/m/Y', $cf, new DateTimeZone('America/Mexico_City'));
                if ($dcf === false)
                    $dcf = null;
                else {
                    $dcf = $dcf->format('Y-m-d');
                }
                if (is_numeric($cc) === true) {
                    $wc = $this->WorkstationConfig->getByWorkstationAndName($workstationId, 'Certificación en piso');
                    $detailData = array(
                        'id' => String::uuid(),
                        'certification_id' => $certificationId,
                        'workstation_config_id' => $wc['WorkstationConfig']['id'],
                        'qualification' => (double) $cc,
                        'certification_date' => $dcf,
                        'status' => 1,
                    );
                    $this->CertificationDetail->save($detailData);
                    $this->CertificationDetail->clear();
                } else {
                    $msg = $user['nomina'] . ' ' . $workstationName . ' Certificación CALIFICACION ERRONEA ' . $cc;
                    $this->log($msg, LOG_ERR);
                }
            } catch (Exception $exc) {
                $msg = $user['nomina'] . ' ' . $workstationName . ' Certificación FECHA ERRONEA ' . $vf;
                $this->log($msg, LOG_ERR);
            }
        }
        if ($def || $dvf || $dcf) {
            $a = array();
            if ($def !== null) {
                $a[] = $def;
            }
            if ($dvf !== null) {
                $a[] = $dvf;
            }
            if ($dcf !== null) {
                $a[] = $dcf;
            }
            usort($a, function ($d, $d2) {
                return $d > $d2;
            });
            $s = $a[0];
            $x = end($a);
            $l = new DateTime($x);
            $l->add(new DateInterval('P' . $w['Workstation']['life'] . 'D'));
            $this->Certification->id = $certificationId;
            $certificationData = array();
            $certificationData['start'] = $s;
            $certificationData['life'] = $l->format('Y-m-d');
            $certificationData['end'] = $x;
            $this->Certification->save($certificationData);
            $this->Certification->clear();
        }
    }

    public function ic($usrLine, $parts, $usr)
    {
        $lineId = '54d7d372-9b84-4cb0-9527-170c1b09678d';
        $this->userLine2($usrLine, $lineId, $usr['id']);
        // CERTIFICACIONES
        $n = '005 ENSAMBLE DE BOOT, RESORTE Y BOBINA';
        $this->certification($n, $usr, $parts, 158, $lineId);
        $n = '015 ENSAMBLE DE TORNILLO Y ENGRASADO DE BOOT';
        $this->certification($n, $usr, $parts, 166, $lineId);
    }

    public function userLine2($usrLine, $lineId, $usrId)
    {
        $fechaIngreso = $usrLine['assign_date'];
        $migrationLevel = $usrLine['level_excel'];
        $days = $usrLine['days'];
        $usrLineData = array(
            'level_excel' => $migrationLevel,
            'assign_date' => $fechaIngreso,
            'days' => $days,
        );
        $this->UserLine->updateUserLine($usrLineData, $usrId, $lineId);
    }

    public function tev($usrLine, $parts, $usr)
    {
        $lineId = '54d7d385-1624-41e6-97bc-170c1b09678d';
        $this->userLine2($usrLine, $lineId, $usr['id']);
        // CERTIFICACIONES
        $n = '05 RIVETEADO DE SUBENSAMBLE';
        $this->certification($n, $usr, $parts, 174, $lineId);
        $n = '015 CALIBRACION DE SUBENSAMBLE';
        $this->certification($n, $usr, $parts, 182, $lineId);
        $n = '025 ENSAMBLE DE HOUSING Y PINES';
        $this->certification($n, $usr, $parts, 190, $lineId);
        $n = '035 ENSAMBLE DE ARMATURE PLATO Y RESORTE';
        $this->certification($n, $usr, $parts, 198, $lineId);
        $n = '045 ENSAMBLE DE COVER';
        $this->certification($n, $usr, $parts, 206, $lineId);
        $n = '055 SOLDADURA LASER';
        $this->certification($n, $usr, $parts, 214, $lineId);
        $n = '060 PRUEBA DE FUGA';
        $this->certification($n, $usr, $parts, 222, $lineId);
        $n = '070 PRUEBA DE FLUJO';
        $this->certification($n, $usr, $parts, 230, $lineId);
        $n = '075 INSCRIPCION LASER';
        $this->certification($n, $usr, $parts, 238, $lineId);
        $n = '085 ENSAMBLE DE GROMMET Y TORNILLO';
        $this->certification($n, $usr, $parts, 246, $lineId);
        $n = '105 SISTEMA DE VISION';
        $this->certification($n, $usr, $parts, 262, $lineId);
    }

    public function dve5nc($usrLine, $parts, $usr)
    {
        $lineId = '54d7d3b9-3188-4fdf-b7c3-170c1b09678d';
        $this->userLine2($usrLine, $lineId, $usr['id']);
        // CERTIFICACIONES
        $n = '10.2 COLOCACION DE HOUSING, WASHER WAVE Y FLECHA';
        $this->certification($n, $usr, $parts, 270, $lineId);
        $n = '020 ENSAMBLE DE MOTOR';
        $this->certification($n, $usr, $parts, 278, $lineId);
        $n = '040 COLOCACION DE PIN';
        $this->certification($n, $usr, $parts, 286, $lineId);
        $n = '070 CARGA DE PLATO';
        $this->certification($n, $usr, $parts, 294, $lineId);
        $n = '090 COLOCACION DE RESORTE PLANO';
        $this->certification($n, $usr, $parts, 302, $lineId);
        $n = '100 COLOCACION DE ENGRANES';
        $this->certification($n, $usr, $parts, 310, $lineId);
        $n = '120 CARGA DE TAPAS Y COLOCACION DE ROTOR';
        $this->certification($n, $usr, $parts, 318, $lineId);
        $n = '195 RETRABAJO';
        $this->certification($n, $usr, $parts, 326, $lineId);
        $n = '220 INSPECCION FINAL,PRUEBA DE FUGA Y EMPAQUE';
        $this->certification($n, $usr, $parts, 334, $lineId);
    }

    public function dve52nc($usrLine, $parts, $usr)
    {
        $lineId = '54d7d3d5-b24c-4094-89d9-170c1b09678d';
        $this->userLine2($usrLine, $lineId, $usr['id']);
        // CERTIFICACIONES
        $i = 342;
        $n = '05 MARCADO LASER DEL CODIGO MATRICIAL 2D';
        $this->certification($n, $usr, $parts, $i, $lineId);

        $i += 8; //350
        $n = '10-A ENSAMBLE DEL MOTOR DC';
        $this->certification($n, $usr, $parts, $i, $lineId);

        $i += 8; //358
        $n = '10-B ENSAMBLE DEL PERNO';
        $this->certification($n, $usr, $parts, $i, $lineId);

        $i += 8; //366
        $n = '20-A ENSAMBLE DE BALERO DE AGUJAS Y FLECHA';
        $this->certification($n, $usr, $parts, $i, $lineId);

        $i += 8; //374
        $n = '20-B ENSAMBLE DE BALERO PLASTICO';
        $this->certification($n, $usr, $parts, $i, $lineId);

        $i += 8; //382
        $n = '30-A ENSAMBLE DEL PLATO EN HOUSING';
        $this->certification($n, $usr, $parts, $i, $lineId);

        $i += 8; //390
        $n = '30-B ATORNILLADO DE PLATO DE GARGANTA';
        $this->certification($n, $usr, $parts, $i, $lineId);

        $i += 8; //398
        $n = '40 ENSAMBLE DE LA UNIDAD DE ACOPLAMIENTO EN EL HOUSING';
        $this->certification($n, $usr, $parts, $i, $lineId);

        $i += 8; //406
        $n = '50 SOLDADURA LASER';
        $this->certification($n, $usr, $parts, $i, $lineId);

        $i += 8; //414
        $n = '60 MAGNETIZACION DEL MAGNETO';
        $this->certification($n, $usr, $parts, $i, $lineId);

        $i += 8; //422
        $n = '65 ENSAMBLE DE PCBA EN LA CUBIERTA DE PLASTICO';
        $this->certification($n, $usr, $parts, $i, $lineId);

        $i += 8; //430
        $n = '70 ENSAMBLE DE ENGRANE INTERMEDIO Y CUBIERTA DE PLASTICO';
        $this->certification($n, $usr, $parts, $i, $lineId);

        $i += 8; //438
        $n = 'ENSAMBLE DE CLIPS';
        $this->certification($n, $usr, $parts, $i, $lineId);

        $i += 8; //446
        $n = '80 PRUEBA DE FUGA DE AIRE';
        $this->certification($n, $usr, $parts, $i, $lineId);

        $i += 8; //454
        $n = '90 APLICACION DE MOLICOTE';
        $this->certification($n, $usr, $parts, $i, $lineId);

        $i += 8; //462
        $n = '120 ENSAMBLE DEL SELLO E IMPRESIÓN DE LA CUBIERTA';
        $this->certification($n, $usr, $parts, $i, $lineId);

        $i += 8; //470
        $n = 'ENSAMBLE DE CLIP, INSPECCION FINAL, EMPAQUE';
        $this->certification($n, $usr, $parts, $i, $lineId);
    }

    public function cover($usrLine, $parts, $usr)
    {
        $lineId = '54d7d447-1d9c-4675-a451-170c1b09678d';
        $this->userLine2($usrLine, $lineId, $usr['id']);
        // CERTIFICACIONES
        $i = 478;
        $n = '10 CARGA Y DESCARGA';
        $this->certification($n, $usr, $parts, $i, $lineId);
    }

    public function maquinados($usrLine, $parts, $usr)
    {
        $lineId = '54d7d438-3c60-48cc-9d0d-170c1b09678d';
        $this->userLine2($usrLine, $lineId, $usr['id']);
        // CERTIFICACIONES
        $i = 487;
        $n = '10 5NC';
        $this->certification($n, $usr, $parts, $i, $lineId);

        $i += 8; //495
        $n = '20 5NC';
        $this->certification($n, $usr, $parts, $i, $lineId);

        $i += 8; //503
        $n = '10 Y 20 5.2';
        $this->certification($n, $usr, $parts, $i, $lineId);

        $i += 8; //511
        $n = '30 5NC,5.2';
        $this->certification($n, $usr, $parts, $i, $lineId);
    }

    public function moldeo($usrLine, $parts, $usr)
    {
        $lineId = '54d81d8c-4554-40aa-947f-170c1b09678d';
        $this->userLine2($usrLine, $lineId, $usr['id']);
        // CERTIFICACIONES
        $i = 518;
        $n = '10 CARGA Y DESCARGA DE SHAFT';
        $this->certification($n, $usr, $parts, $i, $lineId);
    }

}
